package com.shop.front.dao.sms;


import com.shop.domain.sms.SmsCode;
import com.shop.jpa.BaseSQLDao;
import com.shop.jpa.support.QuerySQL;
import com.shop.web.context.WebContext;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Repository;

@Repository
public class SmsCodeSQLDao extends BaseSQLDao {

    /**
     * 分页获取短信验证码记录
     *
     * 注意：此处通过 mobile 关联 user 表，只是为了测试 sharding-sphere 分表关联功能
     *
     * @param ip
     * @param mobile
     * @param todayStr
     * @return
     */
    @Deprecated
    public Page<SmsCode> pageSmsCode(String ip, String mobile, String todayStr) {
        StringBuffer field = new StringBuffer("sc.*");
        String from = "t_sms_code sc left join t_user u on sc.mobile = u.mobile";
        String order = "sc.create_time desc";
        QuerySQL qs = new QuerySQL(WebContext.getPageNo(), WebContext.getPageSize(), field.toString(), from, order);
        qs.addWhereWithoutParams("sc.is_deleted = 0");
        qs.addWhereEqNotBlank("sc.ip", ip);
        qs.addWhereEqNotBlank("sc.mobile", mobile);
        qs.addWhereDateGtNotBlank("sc.create_time", todayStr + "");
        qs.addWhereDateLtNotBlank("sc.create_time", todayStr + " 23:59:59");
        return this.page(qs, SmsCode.class);
    }


}
